package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);not null;unique;comment:'用户名'" json:"username"`
	Password string `gorm:"type:varchar(30);not null;comment:'密码'" json:"password"`
	Status   int    `gorm:"type:tinyint;not null;default:1;comment:'状态 1 正常 2 封禁'" json:"status"`
}

// Create 创建用户
func (u *User) Create() error {
	return DB.Create(&u).Error
}

// 根据用户名查询用户
func (u *User) GetUserByUsername() error {
	return DB.Where("username = ?", u.Username).Limit(1).Find(&u).Error
}
